package com.example.jiaju.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.jiaju.R;

import java.util.List;

public class FurnitureDesignAdapter extends RecyclerView.Adapter<FurnitureDesignAdapter.MyViewHolder> {

    private final List<String> picList;

    public FurnitureDesignAdapter(List<String> picList) {
        this.picList = picList;
    }

    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).
                inflate(R.layout.furniture_design, parent, false);
        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
        //添加数据
        Glide.with(holder.designImg).load(picList.get(position)).into(holder.designImg);
    }

    @Override
    public int getItemCount() {
        return picList.size();
    }

    static class MyViewHolder extends RecyclerView.ViewHolder {
        private final ImageView designImg;

        public MyViewHolder(@NonNull View itemView) {
            super(itemView);
            designImg = itemView.findViewById(R.id.furniture_design_img);
        }
    }
}
